/*******************************************************************************
 * Copyright (c) 2002 Boris Pruessmann and others. All rights reserved. This
 * program and the accompanying materials are made available under the terms of
 * the Common Public License v0.5 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation
 ******************************************************************************/
package net.sourceforge.perforce.internal.api;

import java.io.InputStream;

import org.eclipse.core.runtime.IStatus;

import net.sourceforge.perforce.core.internal.api.Depots;

/**
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 * @version $Revision: 488 $
 */
public class DepotsTest extends ClientUserTestCase {
  // ---------------------------------------------------------------------------
  // Private Variables

  /** Stores the Depots object. */
  private Depots clientUser;

  // -------------------------------------------------------------------------
  // Public Constructors

  /**
   * Constructor for DepotsTest.
   * 
   * @param name the name of the test.
   */
  public DepotsTest(String name) {
    super(name);
  }

  //----------------------------------------------------------------------------
  // -- Public Methods

  /** Tests the ClientUser with unspecified password. */
  public void testInvalidOrUnsetPassword() throws Exception {
    InputStream script = getClass().getResourceAsStream("invalidOrUnsetPassword.xml");
    executeScript(script, clientUser);

    assertTrue(!clientUser.getStatus().isOK());
    assertEquals(IStatus.ERROR, clientUser.getStatus().getSeverity());
  }

  /** Tests the ClientUser without permissions. */
  public void testPermissionDenied() throws Exception {
    InputStream script = getClass().getResourceAsStream("permissionDenied.xml");
    executeScript(script, clientUser);

    assertTrue(!clientUser.getStatus().isOK());
    assertEquals(IStatus.ERROR, clientUser.getStatus().getSeverity());
  }

  /** Tests the ClientUser with a valid result. */
  public void testValidResult() throws Exception {
    InputStream script = getClass().getResourceAsStream("depots_validResult.xml");
    executeScript(script, clientUser);

    assertTrue(clientUser.getStatus().isOK());

    String[] result = clientUser.getResult();
    String[] expected = {"//depot", "//eclipse", "//p4eclipse", "//projects", "//se"};
    assertEquals(expected.length, result.length);
    for (int i = 0; i < result.length; i++) {
      assertEquals(expected[i], result[i]);
    }
  }

  // ---------------------------------------------------------------------------
  // Protected Methods

  @Override
  protected void setUp() throws Exception {
    super.setUp();

    clientUser = Depots.newInstance(null);
  }
}
